﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ZGEDrySaltery.BLL;
using ZGEDrySaltery.Code;
using ZGEDrySaltery.DTO;
using ZGEDrySaltery.Model;

namespace ZGEDrySaltery.Web.Areas.SystemManage.Controllers
{
    public class OfferController : ControllerBase
    {
        #region 获取商品列表
        /// <summary>
        /// 商品列表
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="JsonPara"></param>
        /// <returns></returns>
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string JsonPara)
        {
            OfferPara SearchDto = JsonPara != null ? JsonHelper.JsonToEntity<OfferPara>(JsonPara) : new OfferPara();
            var data = new
            {
                rows = OfferBLL.GetInstance().GetOfferList(pagination, SearchDto),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        #endregion

        #region 获取分类列表
        /// <summary>
        /// 获取分类列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetTreeSelectJson()
        {
            List<ObjectCategoryModel> data = ObjectCategoryBLL.GetInstance().GetObjectCategoryList();
            var treeList = new List<TreeSelectModel>();
            if (data != null)
            {
                foreach (ObjectCategoryModel item in data)
                {
                    TreeSelectModel treeModel = new TreeSelectModel();
                    treeModel.id = item.PCID.ToString();
                    treeModel.text = item.NAME;
                    treeModel.parentId = item.PREPCID.ToString();
                    treeList.Add(treeModel);
                }
            }

            return Content(treeList.TreeSelectJson());
        }
        #endregion

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            OfferModel data = OfferBLL.GetInstance().GetFormOffer(Convert.ToInt32(keyValue));
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(OfferModel userEntity, string keyValue)
        {
            //userApp.SubmitForm(userEntity, userLogOnEntity, keyValue);
            return Success("操作成功。");
        }
    }
}
